package com.hgshop.yudongyang.controller;

import java.util.List;

import org.apache.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hgshop.yudongyang.domain.Category;
import com.hgshop.yudongyang.service.CategoryService;

@RequestMapping("cat")
@Controller
public class CatController {

	@Reference
	CategoryService categoryService;

	@RequestMapping("list")
	public String list() {

		return "category/list";
	}

	@PostMapping("getTree")
	@ResponseBody
	public List<Category> getTree() {

		List<Category> list = categoryService.getTree(0);

		return list;
	}

	@PostMapping("addCategory")
	@ResponseBody
	public boolean addCategory(Category c) {
		try {
			categoryService.addCategory(c);
			return true;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return false;
		}
	}
	@PostMapping("delCategory")
	@ResponseBody
	public boolean delCategory(Category c) {
		try {
			categoryService.delCategory(c);
			return true;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return false;
		}
	}
	@PostMapping("updateCategory")
	@ResponseBody
	public boolean updateCategory(Category c) {
		System.out.println(c);
		try {
			categoryService.updateCategory(c);
			return true;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return false;
		}
	}

}
